#include "uidmanager.h"

UidManager * UidManager::m_instance = 0;

UidManager::UidManager(QObject *parent) :
    QObject(parent)
{
    if (m_instance)
        qWarning("UidManager already has instance");
    m_instance = this;
}

UidManager::~UidManager()
{
    m_instance = 0;
}

UidManager * UidManager::instance()
{
    return m_instance;
}

int UidManager::uniqueIndentifier(const QString &id)
{
    int uid;

    if (!m_uniqueIdentifiers.contains(id)) {
        uid = m_uniqueIdentifiers.count();
        m_uniqueIdentifiers.insert(id, uid);
    } else {
        uid = m_uniqueIdentifiers.value(id, -1);
    }
    return uid;
}

QString UidManager::stringForUniqueIndentifier(int id) const
{
    return m_uniqueIdentifiers.key(id, QString());
}
